package org.zn.etl.misc;

import java.math.BigDecimal;
import java.util.Objects;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class CompareUtils {

	public static boolean valueEquals(Object o1, Object o2) {

		log.debug("Compare o1 class:{} value:{}  , o2 class:{} value:{}   ",o1.getClass(),o1 ,o2.getClass(),o2);
		
		boolean eq = false;

		if (o1 instanceof Number && o2 instanceof Number) {

			if (o1 == null || o2 == null) {
				return false;
			}
			else {
				
				Number n1=(Number) o1;
				Number n2=(Number) o2;
				eq =  Double.compare(n1.doubleValue(), n2.doubleValue())==0;
				log.debug("do Double flat Compare  d1:{} ,d2:{}  eq:{},",n1,n2,eq);
				
			}

		}
		else {
			
			eq = Objects.equals(o1, o2);
			log.debug("do other Compare  o1:{} ,o2:{}  eq:{},",o1,o2,eq);
			
		}

		return eq;
	}

	public static void main(String[] args) {

		System.out.println(valueEquals(new BigDecimal("40473600.432"), new BigDecimal("40473600.432")));
		
		System.out.println(valueEquals(new BigDecimal(40473600l), new BigDecimal("40473600.00")));
		
		System.out.println(valueEquals(new BigDecimal(40473600l), new BigDecimal(40473600.00)));
		
		System.out.println(valueEquals(new BigDecimal(40473600.64576), new BigDecimal(40473600.645716)));

	}

}
